#!/usr/bin/env python
""" Test the netio.py - client """

from netio import *

import socket
import time

if __name__ == '__main__':
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
    sock_fd = sock.fileno()  
    
    sock.setblocking(1) # blocking client
    sock.connect(('127.0.0.1', 15000))

    data = "hello, world\n"
    data_len = len(data)
    sended = 0
    while sended < data_len:
        sended += sock.send(data)

    sock.setblocking(0) # blocking client
    sock.settimeout(10)
    readed = ''
    try:
        while True:
            data = sock.recv(1024)
            print "Get %s" % data
            if not data: 
                break
            readed += data 
    except socket.timeout, e:
        pass
    print "@@@@%s" % readed

    time.sleep(1000)
    sock.close()
